package com.producer.test;

import com.alibaba.rocketmq.client.exception.MQClientException;
import com.alibaba.rocketmq.client.producer.LocalTransactionExecuter;
import com.alibaba.rocketmq.client.producer.LocalTransactionState;
import com.alibaba.rocketmq.client.producer.SendResult;
import com.alibaba.rocketmq.common.message.Message;
import com.producer.MfTxmessageClient;



public class SendHalfMessage {
  public static void main(String args[]) throws MQClientException{
	  
	  MfTxmessageClient txProducerClient = new MfTxmessageClient();
	  //MfTxmessageClient 不是aif的方法,自己写了个测试
		//String topic, String tags, String keys, byte[] body
	  Message msg =  new Message("ROCKET_A","tag*", "KEY124" + 5,
                  ("Hello ROCKET_A " + 1).getBytes());
		
		LocalTransactionExecuter excutor = new LocalTransactionExecuter() {
			public LocalTransactionState executeLocalTransactionBranch(Message message,
					Object obj) {
				try {
					System.out.println("业务开始");
					//Thread.sleep(50000);
					System.out.println("业务成功");
				} catch (Exception e) {
					return LocalTransactionState.ROLLBACK_MESSAGE;
				}
				return LocalTransactionState.COMMIT_MESSAGE;
			}
		};
		System.out.print("begin send");
		SendResult  sr = txProducerClient.send( msg, excutor);
		System.out.print("end");
  }
}
